import {ref} from "vue";
import {mainStore} from "../store/store.ts";
import {storeToRefs} from "pinia";

export function useHeaderUserInfomation() {
    const store = mainStore()
    const {userName} = storeToRefs(store)
    // const Name = ref<string>(userName)
    const vermicelli = ref<number>(123450)
    const caseSum = ref<number>(77)
    const like = ref<number>(1234567)
    const isVip = ref<boolean>(true)
    const iconUrl = ref<string>('')

    function getIconVip() {
        if (isVip.value) {
            iconUrl.value = '/assets/vip.png'
        } else {
            iconUrl.value = '/assets/noVip.png'
        }
    }

    function getWholeNum(data: number | string): string {
        let strData = data.toString()
        let length = strData.length

        if (length > 4) {
            let res = strData.split("").splice(0, length - 4).join("")
            return res + "W"
        } else if (length > 3) {
            let res = strData.split("").splice(0, length - 3).join("")
            return res + "K"
        }
        return strData
    }

    getIconVip();
    return {
        userName, vermicelli, caseSum, like, iconUrl, getWholeNum
    }
}